package com.train.mgr.modules.biz.controller;

import com.train.common.model.PageResult;
import com.train.common.model.R;
import com.train.mgr.modules.biz.dto.request.StatQueryDTO;
import com.train.mgr.modules.biz.dto.request.StatViewDTO;
import com.train.mgr.modules.biz.entity.*;
import com.train.mgr.modules.biz.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 课程/课时学习总览统计表 前端控制器
 * @author cxg
 * @date 2025-10-11
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@Api( tags = "课程学习统计")
@RequestMapping("/stat_course_study")
public class StatCourseStudyController {

    private final IStatCourseOverviewService statCourseOverviewService;

    private final IStatLessonTraineeService statLessonTraineeService;

    private final IStatLessonGroupService statLessonGroupService;

    private final IStatCourseGroupService statCourseGroupService;

    private final IStatCourseTraineeService statCourseTraineeService;


    @GetMapping("/course_overview_list")
    @ApiOperation("统计课程总概览)")
    public R<PageResult<StatCourseOverview>> courseOverviewList(StatViewDTO params) {
        return R.succeed(statCourseOverviewService.courseOverviewList(params));
    }

    @GetMapping("/course_overview_list/flush")
    @ApiOperation("统计课程总概览-刷新")
    public R<PageResult<StatCourseOverview>> courseOverviewFlush(@RequestParam(name = "courseId", required = false) String courseId) {
        statCourseOverviewService.buildLessonTraineeStat(courseId);
        return R.succeed("操作成功");
    }

    @GetMapping("/lesson_trainee_list")
    @ApiOperation("统计课时列表(学员)")
    public R<PageResult<StatLessonTrainee>> lessonTraineeList(StatQueryDTO params) {
        return R.succeed(statLessonTraineeService.lessonTraineeList(params));
    }

    @GetMapping("/lesson_trainee_list/flush")
    @ApiOperation("统计课时列表(学员)-刷新")
    public R<PageResult<StatLessonTrainee>> lessonTraineeFlush(@RequestParam(name = "courseId", required = false) String courseId) {
        statLessonTraineeService.buildLessonTraineeStat(courseId);
        return R.succeed("操作成功");
    }

    @GetMapping("/lesson_group_list")
    @ApiOperation("统计课时列表(分组)")
    public R<PageResult<StatLessonGroup>> lessonGroupList(StatQueryDTO params) {
        return R.succeed(statLessonGroupService.lessonGroupList(params));
    }

    @GetMapping("/lesson_group_list/flush")
    @ApiOperation("统计课时列表(分组)-刷新")
    public R<PageResult<StatLessonGroup>> lessonGroupFlush(@RequestParam(name = "courseId", required = false) String courseId) {
        statLessonGroupService.buildLessonTraineeStat(courseId);
        return R.succeed("操作成功");
    }


    @GetMapping("/course_trainee_list")
    @ApiOperation("统计课程列表(学员)")
    public R<PageResult<StatCourseTrainee>> courseTraineeList(StatQueryDTO params) {
        return R.succeed(statCourseTraineeService.courseTraineeList(params));
    }

    @GetMapping("/course_trainee_list/flush")
    @ApiOperation("统计课程列表(学员)-刷新")
    public R<PageResult<StatCourseTrainee>> courseTraineeFlush(@RequestParam(name = "courseId", required = false) String courseId) {
        statCourseTraineeService.buildLessonTraineeStat(courseId);
        return R.succeed("操作成功");
    }

    @GetMapping("/course_group_list")
    @ApiOperation("统计课程列表(分组)")
    public R<PageResult<StatCourseGroup>> courseGroupList(StatQueryDTO params) {
        return R.succeed(statCourseGroupService.courseGroupList(params));
    }

    @GetMapping("/course_group_list/flush")
    @ApiOperation("统计课程列表(分组)-刷新")
    public R<PageResult<StatCourseGroup>> courseGroupFlush(@RequestParam(name = "courseId", required = false) String courseId) {
        statCourseGroupService.buildLessonTraineeStat(courseId);
        return R.succeed("操作成功");
    }

}
